export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '上周',
          onClick(picker) {
            const dataValue = new Date()
            const year = dataValue.getFullYear()
            const month = dataValue.getMonth() + 1
            const day = dataValue.getDate()
            var thisWeekStart // 本周周一的时间
            if (dataValue.getDay() === 0) {
              // 周天的情况；
              thisWeekStart =
                                new Date(year + '/' + month + '/' + day).getTime() -
                                (dataValue.getDay() + 6) * 86400000
            } else {
              thisWeekStart =
                                new Date(year + '/' + month + '/' + day).getTime() -
                                (dataValue.getDay() - 1) * 86400000
            }
            const prevWeekStart = thisWeekStart - 7 * 86400000 // 上周周一的时间
            const prevWeekEnd = thisWeekStart - 1 * 86400000 // 上周周日的时间
            const start = new Date(prevWeekStart) // 开始时间
            const end = new Date(prevWeekEnd) // 结束时间
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '本周',
          onClick(picker) {
            const dataValue = new Date()
            const year = dataValue.getFullYear()
            const month = dataValue.getMonth() + 1
            const day = dataValue.getDate()
            var thisWeekStart // 本周周一的时间
            if (dataValue.getDay() === 0) {
              // 周天的情况；
              thisWeekStart =
                                new Date(year + '/' + month + '/' + day).getTime() -
                                (dataValue.getDay() + 6) * 86400000
            } else {
              thisWeekStart =
                                new Date(year + '/' + month + '/' + day).getTime() -
                                (dataValue.getDay() - 1) * 86400000
            }
            const prevWeekStart = thisWeekStart // 上周周一的时间
            const prevWeekEnd = thisWeekStart + 6 * 86400000 // 上周周日的时间
            const start = new Date(prevWeekStart) // 开始时间
            const end = new Date(prevWeekEnd) // 结束时间
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '下周',
          onClick(picker) {
            const dataValue = new Date()
            const year = dataValue.getFullYear()
            const month = dataValue.getMonth() + 1
            const day = dataValue.getDate()
            var thisWeekStart // 本周周一的时间
            if (dataValue.getDay() === 0) {
              // 周天的情况；
              thisWeekStart =
                                new Date(year + '/' + month + '/' + day).getTime() -
                                (dataValue.getDay() + 6) * 86400000
            } else {
              thisWeekStart =
                                new Date(year + '/' + month + '/' + day).getTime() -
                                (dataValue.getDay() - 1) * 86400000
            }
            const prevWeekStart = thisWeekStart + 7 * 86400000 // 上周周一的时间
            const prevWeekEnd = thisWeekStart + 13 * 86400000 // 上周周日的时间
            const start = new Date(prevWeekStart) // 开始时间
            const end = new Date(prevWeekEnd) // 结束时间
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '上月',
          onClick(picker) {
            const end = gettimeEnd()
            const start = gettimeStart()
            picker.$emit('pick', [start, end])
            function gettimeStart() {
              const nowdays = new Date()
              let year = nowdays.getFullYear()
              let month = nowdays.getMonth()
              if (month === 0) {
                month = 12
                year = year - 1
              }
              if (month < 10) {
                month = '0' + month
              }
              let firstDayOfPreMonth = year + '-' + month + '-' + '01'
              firstDayOfPreMonth = firstDayOfPreMonth.toString()
              return new Date(firstDayOfPreMonth)
            }
            function gettimeEnd() {
              const nowdays = new Date()
              let year = nowdays.getFullYear()
              let month = nowdays.getMonth()
              if (month === 0) {
                month = 12
                year = year - 1
              }
              if (month < 10) {
                month = '0' + month
              }
              const lastDay = new Date(year, month, 0)
              let lastDayOfPreMonth = year + '-' + month + '-' + lastDay.getDate()
              lastDayOfPreMonth = lastDayOfPreMonth.toString()
              return new Date(lastDayOfPreMonth)
            }
          }
        }, {
          text: '本月',
          onClick(picker) {
            const end = gettimeEnd()
            const start = gettimeStart()
            picker.$emit('pick', [start, end])
            function gettimeStart() {
              const nowdays = new Date()
              let year = nowdays.getFullYear()
              let month = nowdays.getMonth()
              if (month === 0) {
                month = 12
                year = year - 1
              }
              if (month < 10) {
                month = '0' + Number(month + 1)
              }
              let firstDayOfPreMonth = year + '-' + month + '-' + '01'
              firstDayOfPreMonth = firstDayOfPreMonth.toString()
              return new Date(firstDayOfPreMonth)
            }
            function gettimeEnd() {
              const nowdays = new Date()
              let year = nowdays.getFullYear()
              let month = nowdays.getMonth()
              if (month === 0) {
                month = 12
                year = year - 1
              }
              if (month < 10) {
                month = '0' + Number(month + 1)
              }
              const lastDay = new Date(year, month, 0)
              let lastDayOfPreMonth = year + '-' + month + '-' + lastDay.getDate()
              lastDayOfPreMonth = lastDayOfPreMonth.toString()
              return new Date(lastDayOfPreMonth)
            }
          }
        }, {
          text: '下月',
          onClick(picker) {
            const end = gettimeEnd()
            const start = gettimeStart()
            picker.$emit('pick', [start, end])
            function gettimeStart() {
              const nowdays = new Date()
              let year = nowdays.getFullYear()
              let month = nowdays.getMonth()
              if (month === 0) {
                month = 12
                year = year - 1
              }
              if (month < 10) {
                month = '0' + Number(month + 2)
              }
              let firstDayOfPreMonth = year + '-' + month + '-' + '01'
              firstDayOfPreMonth = firstDayOfPreMonth.toString()
              return new Date(firstDayOfPreMonth)
            }
            function gettimeEnd() {
              const nowdays = new Date()
              let year = nowdays.getFullYear()
              let month = nowdays.getMonth()
              if (month === 0) {
                month = 12
                year = year - 1
              }
              if (month < 10) {
                month = '0' + Number(month + 2)
              }
              const lastDay = new Date(year, month, 0)
              let lastDayOfPreMonth = year + '-' + month + '-' + lastDay.getDate()
              lastDayOfPreMonth = lastDayOfPreMonth.toString()
              return new Date(lastDayOfPreMonth)
            }
          }
        }]
      }
    }
  },
  created() {
    this.jinnian()
  },
  methods: {
    // 上月
    shangyue() {
      const end = gettimeEnd()
      const start = gettimeStart()
      this.timers = [start, end]
      function gettimeStart() {
        const nowdays = new Date()
        let year = nowdays.getFullYear()
        let month = nowdays.getMonth()
        if (month === 0) {
          month = 12
          year = year - 1
        }
        if (month < 10) {
          month = '0' + month
        }
        let firstDayOfPreMonth = year + '-' + month + '-' + '01'
        firstDayOfPreMonth = firstDayOfPreMonth.toString()
        return firstDayOfPreMonth
      }
      function gettimeEnd() {
        const nowdays = new Date()
        let year = nowdays.getFullYear()
        let month = nowdays.getMonth()
        if (month === 0) {
          month = 12
          year = year - 1
        }
        if (month < 10) {
          month = '0' + month
        }
        const lastDay = new Date(year, month, 0)
        let lastDayOfPreMonth = year + '-' + month + '-' + lastDay.getDate()
        lastDayOfPreMonth = lastDayOfPreMonth.toString()
        return lastDayOfPreMonth
      }
    },
    // 本月
    benyue() {
      const end = gettimeEnd()
      const start = gettimeStart()
      this.timers = [start, end]
      function gettimeStart() {
        const nowdays = new Date()
        let year = nowdays.getFullYear()
        let month = nowdays.getMonth()
        if (month === 0) {
          month = 12
          year = year - 1
        } else if (month < 9) {
          month = '0' + Number(month + 1)
        } else {
          month = Number(month + 1)
        }
        let firstDayOfPreMonth = year + '-' + month + '-' + '01'
        firstDayOfPreMonth = firstDayOfPreMonth.toString()
        return firstDayOfPreMonth
      }
      function gettimeEnd() {
        const nowdays = new Date()
        let year = nowdays.getFullYear()
        let month = nowdays.getMonth()
        if (month === 0) {
          month = 12
          year = year - 1
        } else if (month < 9) {
          month = '0' + Number(month + 1)
        } else {
          month = Number(month + 1)
        }
        const lastDay = new Date(year, month, 0)
        let lastDayOfPreMonth = year + '-' + month + '-' + lastDay.getDate()
        lastDayOfPreMonth = lastDayOfPreMonth.toString()
        return lastDayOfPreMonth
      }
    },
    // 今年
    jinnian() {
      const end = new Date().toLocaleDateString().split('/').join('-')
      const start = gettimeStart()
      this.timers = [start, end]
      function gettimeStart() {
        const nowdays = new Date()
        const year = nowdays.getFullYear()
        const lastDayOfPreMonth = year + '-01-01'
        return lastDayOfPreMonth
      }
    },
    // 当前月 2023-08
    getMonths1() {
      const nowdays = new Date()
      let year = nowdays.getFullYear()
      let month = nowdays.getMonth()
      if (month < 9) {
        month = '0' + Number(month + 1)
      } else {
        month = Number(month + 1)
      }
      let firstDayOfPreMonth = year + '-' + month
      firstDayOfPreMonth = firstDayOfPreMonth.toString()
      this.month = firstDayOfPreMonth
    }
  }
}
